home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: howland.reston.ans.net!psinntp!psinntp!psinntp!psinntp!bbnews1!trsvr!news
- From: Benjamin Romer <bmr1@trpo4.tr.unisys.com>
- Subject: Re: Is there a standard for * and & placement style?
- Sender: news@tr.unisys.com (cnews news id.)
- Message-ID: <312B5F0F.CFE@trpo4.tr.unisys.com>
- Date: Wed, 21 Feb 1996 18:06:07 GMT
- X-Nntp-Posting-Host: bmr1.tr.unisys.com
- Content-Transfer-Encoding: 7bit
- Content-Type: text/plain; charset=us-ascii
- References: <3128BD31.4AF8@wildfire.com> <marnoldDn27q9.Is0@netcom.com>
- <4gckd5$bc7@clarknet.clark.net> <egpwb896e6.fsf@vipe.ii.uib.no>
- Mime-Version: 1.0
- X-Mailer: Mozilla 2.0 (WinNT; I)
- Organization: Unisys Corp.
-
- Ketil Z Malde wrote:
- >
- > Discussing
- >
- > int *ip;
- > vs. int* ip;
- >
- > one might also observe that "*ip" is, in fact, an int, just as much as
- > "ip" is an int*. Just my two *.
- >
- > -kzm
- >
-
- Actually there has been a great deal of argument about which is considered
- "correct", even though both work.
-
- IMHO, the first method (int *ip) is safer for beginners, who might expect
-
- int* a, b, c;
-
- To define three pointers, while it in fact only defines one. This belief is
- further reinforced in a beginner's view by the use of * in typecasting,
- e.g. you must write (int*)ptrToAChar to get a pointer; if you write
- (int)*ptrToAChar you actually get an int. (I know you don't have to typecast
- char to int, it's only an example.) If you only define one variable per
- statement, though, it looks and works just fine; personally, I'd write
-
- int *a, *b, *c;
-
- But that may just be stubbornness (and the fact that I've been using
- that format since college). Some would even go so far as to insist on
- using a typedef for pointers:
-
- typedef int * ptrInt;
-
- ptrInt ip, a, b, c;
-
- This may be the safest way to do it but personally I think its a waste
- of typing.
-
- This is all merely opinion, though, and it really doesn't matter what you
- use as long as it compiles and your meaning is clear.
-
- $0.02
-
- Freely yours,
-
- Ben Romer
- Software Engineer
- Unisys Corporation
-
- #include <stddisclaim.h>
-